package com.rocsun.web.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.rocsun.base.RocsunResult;
import com.rocsun.constant.ControllerConstant;
import com.rocsun.service.UserService;
import com.rocsun.user.param.UserRequest;
import com.rocsun.user.result.UserVO;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @program: rocsun-scali
 * @description:
 * @author: yx.guo
 * @create: 2025-10-18 19:28
 **/
@RestController
@RequestMapping(ControllerConstant.USER_API)
public class UserController {

    @Resource
    private UserService userService;

    @PostMapping("/page")
    public RocsunResult<IPage<UserVO>> page(@RequestBody UserRequest userRequest) {
        return RocsunResult.success(userService.page(userRequest));
    }

    @GetMapping("/query/userName/{userName}")
    public RocsunResult<UserVO> queryByUserName(@PathVariable(value = "userName") String userName) {
        return RocsunResult.success(userService.getByUserName(userName));
    }

    @GetMapping("/query/{id}")
    public RocsunResult<UserVO> queryById(@PathVariable(value = "id") String id) {
        return RocsunResult.success(userService.getByUserName(id));
    }

    @PostMapping("/update")
    public RocsunResult<Boolean> update(@RequestBody UserRequest request) {
        return RocsunResult.success(userService.update(request));
    }

    @DeleteMapping("/physicalDelete/{id}")
    public RocsunResult<Boolean> delete(@PathVariable("id") Long id) {
        return RocsunResult.success(userService.physicalDelete(id));
    }

    @PostMapping("/logicDelete/{id}")
    public RocsunResult<Boolean> logicDelete(@PathVariable("id") Long id) {
        return RocsunResult.success(userService.logicDelete(id));
    }

    @PostMapping("/create")
    public RocsunResult<Integer> create(@RequestBody UserRequest request) {
        return RocsunResult.success(userService.create(request));
    }

}
